<script setup lang="ts">
import { BookRequestParams, RequestParams } from "@/api/book/type";
import {
  bookList,
  addbook,
  delbook,
  Formbook,
  LibraryOptions,
  updatebook,
  upAndDown,
  BookshelfOptions,
  importLib,
  importOnShelf,
  importOffShelf,
  exportBook,
  syncBookAdd,
} from "@/api/book/index.ts";

import { ElLoading, ElMessage, ElMessageBox } from "element-plus";
import { computed, onMounted, reactive, ref } from "vue";
import useUserStore from "@/store/modules/user";
let useStore = useUserStore();
const hasRole = (role: any) => {
  return useStore.user.roles.includes(role);
};
// ================================================================================
// ref
const queryFormRef = ref(); //搜索
const ruleFormRef = ref(); //弹框表单

const ids = ref([] as number[]); //表格全选
const total = ref();
const loading = ref(false);
const dialogVisible = ref(false);
const title = ref("新增");
let LibOptions = ref([] as any);
const ruleForm = ref({} as any);
let queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  // bookCode: "",
  // keyword: "",
} as RequestParams);
const tableList = ref([{}] as BookRequestParams[]);
// 正则表达式，用于匹配纯数字、纯字母、纯中文或纯标点
const regex = /^(?![0-9]+$)(?![a-zA-Z]+$)(?![\u4e00-\u9fa5]+$)(?![.,!?;:]+$).*/;

const rules = reactive({
  bookRfid: [
    { required: true, message: "图书rfid不能为空", trigger: "blur" },
    {
      validator: (rule, value, callback) => {
        if (!value) {
          return callback(new Error("图书编号不能为空"));
        }

        // 正则表达式：不能纯数字或纯字母，且不能包含标点符号和中文
        if (!/^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]+$/.test(value)) {
          return callback(
            new Error(
              "必须包含至少一个字母和一个数字，且不能包含标点符号和中文"
            )
          );
        }

        callback();
      },
      trigger: "blur",
    },
  ],
  bookName: [{ required: true, message: "图书名称不能为空", trigger: "blur" }],
  spineName: [{ required: true, message: "书脊名称不能为空", trigger: "blur" }],
  libraryId: [
    { required: true, message: "请选择图书馆", trigger: "change" },
    // { min: 1, max: 5, message: "请输入1到5位", trigger: "blur" },
  ],
  bookCode: [
    { required: true, message: "图书编号不能为空", trigger: "blur" },
    {
      validator: (rule, value, callback) => {
        if (!value) {
          return callback(new Error("图书编号不能为空"));
        }

        // 正则表达式：必须包含至少一个字母和一个数字，且不能包含标点符号和中文
        const reg = /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d【】()[\]]*$/;
        if (!reg.test(value)) {
          return callback(
            new Error(
              "必须包含至少一个字母和一个数字，且不能包含标点符号和中文"
            )
          );
        }

        callback();
      },
      trigger: "blur",
    },
    { min: 1, max: 50, message: "图书编号过长", trigger: "blur" },
  ],
});
// 挂载
onMounted(() => {
  handleQuery();
});
// ================================================================================

/**
 * 查询
 */
const searchQuery = async () => {
  if (!queryParams.bookCode && !queryParams.keyword) {
    ElMessage.error("搜索不能为空");
    return;
  }
  try {
    loading.value = true;
    queryParams.keyword = queryParams.keyword;
    queryParams.bookCode = queryParams.bookCode;
    const res = await bookList(queryParams);
    //console.log(res, "res列表");

    tableList.value = res.data.records;

    total.value = res.data.total;
    loading.value = false;
  } catch (error) {
    // console.error(error);
    loading.value = false; // 将 loading 的值设置为 false，以便停止加载动画
  }
};
const handleQuery = async () => {
  try {
    loading.value = true;
    const res = await bookList(queryParams);
    //console.log(res, "res列表");
    tableList.value = res.data.records;
    total.value = res.data.total;
    loading.value = false;
  } catch (error) {
    // console.error(error);
    loading.value = false; // 将 loading 的值设置为 false，以便停止加载动画
  }
};
/**
 * 重置
 */
const resetQuery = () => {
  queryFormRef.value.resetFields();
  queryParams.pageNum = 1;
  queryParams.bookCode = "";
  queryParams.keyword = "";
  queryFormRef.value.clearValidate();
  handleQuery();
};
/**
 * 行checkbox change事件
 */
function handleSelectionChange(selection: any) {
  ids.value = selection.map((item: any) => item.id);
}
/**
 * 打开弹框
 */
const openDialog = async (id?: number) => {
  dialogVisible.value = true;
  const res = await LibraryOptions(useStore.encryptedData);
  LibOptions.value = res.data;
  // console.log(LibOptions.value, "LibOptions图书下拉");

  if (id) {
    const res = await Formbook(id as any);
    ruleForm.value = res.data;
    // console.log(res, "addFormUser");
    title.value = "修改图书";
  } else {
    title.value = "新增图书";

    if (ruleFormRef.value) {
      ruleFormRef.value.clearValidate();
    }
    ruleForm.value = {};
  }
};
/**
 * 关闭弹框
 */
const close = () => {
  dialogVisible.value = false;
  ruleForm.value = {} as any;
  ruleFormRef.value.resetFields();
  ruleFormRef.value.clearValidate();
};
/**
 * 处理表单提交事件
 */
const submit = async () => {
  ruleFormRef.value.validate((valid: any) => {
    if (valid) {
      const userId = ruleForm.value.id;
      loading.value = true;
      if (userId) {
        // console.log(ruleForm.value, "编辑");
        updatebook(ruleForm.value)
          .then((res) => {
            if (res.code == 200) {
              ElMessage.success("图书修改成功");
              close();
              handleQuery();
            } else {
              ElMessage.error(res.msg);
            }
          })
          .finally(() => (loading.value = false));
      } else {
        //  console.log("新增");
        addbook(ruleForm.value)
          .then((res) => {
            if (res.code == 200) {
              ElMessage.success("图书新增成功");
              close();
              handleQuery();
            } else {
              ElMessage.error(res.msg);
            }
          })
          .finally(() => (loading.value = false));
      }
    }
  });
};

/**
 * 删除
 */
const dell = (id: any) => {
  const userIds = [id || ids.value].join(",");
  if (!userIds) {
    ElMessage.warning("请勾选删除项");
    return;
  }
  ElMessageBox.confirm("确认删除吗?", "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(function () {
    // console.log(Number(userIds), userIds);
    delbook(id).then((res) => {
      if (res.code == 200) {
        ElMessage.success("删除成功");
        handleQuery();
      }
    });
  });
};

const handleSizeChange = (val: number) => {
  queryParams.pageSize = val;
  queryParams.pageNum = 1;

  handleQuery();
};
const handleCurrentChange = (val: number) => {
  queryParams.pageNum = val;
  handleQuery();
  window.scrollTo({ top: 0, behavior: "smooth" }); // 立即回到顶部，并使用平滑滚动效果
};

/**
 * 枚举
 */
const getbooksStatus = (status: number) => {
  const STATUSES = [
    { id: 0, name: "下架" },
    { id: 1, name: "上架" },
  ];
  const matched = STATUSES.find((item) => item.id === status);
  return matched ? matched.name : "";
};
const booksStatus = (status: number) => {
  const STATUSES = [
    { id: 0, name: "上架" },
    { id: 1, name: "下架" },
  ];
  const matched = STATUSES.find((item) => item.id === status);
  return matched ? matched.name : "";
};
// -----------------------------------------------------------------
// 修改上下架状态

const locationOpt = ref();
const FormRef = ref();
const Formrule = ref({} as any);
const dialog = ref(false);
const rule = reactive({
  libraryId: [{ required: true, message: "请选择图书馆", trigger: "change" }],

  bookshelfId: [
    { required: true, message: "请选择书架位置", trigger: "change" },
  ],
  bookshelfLayer: [
    { required: true, message: "请输入所在书架层数", trigger: "blur" },
    {
      pattern: /^(?:[1-9]|10)$/,
      message: "最大书架层数为1-10",
      trigger: "blur",
    },
  ],
});
const booklibraryId = ref(null as any);
const bookLocationItem = ref(null as any); // 创建一个ref引用
const clearBookLocationValidation = () => {
  bookLocationItem.value.clearValidate(); // 调用clearValidate方法清除校验状态
  booklibraryId.value.clearValidate();
};
const editStatus = async (row: any) => {
  Formrule.value.id = row.id;
  //console.log(row);
  Formrule.value.bookName = row.bookName;
  if (row.bookStatus === 1) {
    ElMessageBox.confirm("确认下架该图书吗?", "警告", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }).then(async function () {
      Formrule.value.bookStatus = 0;
      const res = await upAndDown(Formrule.value);
      if (res.code === 200) {
        // 关闭对话框并重新查询列表数据
        loading.value = false;
        handleQuery();
        ElMessage.success("该图书下架成功");
        row.bookStatus = 1;
        closedialog();
        clearBookLocationValidation();
      }
    });
  } else {
    dialog.value = true;
    Formrule.value.bookLocationId = "";
    const res = await LibraryOptions(useStore.encryptedData);
    clearBookLocationValidation();
    LibOptions.value = res.data;
    // console.log(LibOptions.value, "上架图书下拉");
  }
};
const closedialog = () => {
  dialog.value = false;

  Formrule.value = {} as any;
  clearBookLocationValidation();
  FormRef.value.resetFields();
};

const sbt = async () => {
  try {
    // 表示当前页面正在异步处理中
    loading.value = true;
    // 验证表单数据是否合法
    const isValid = await FormRef.value.validate();
    if (isValid) {
      const res = await upAndDown(Formrule.value);
      if (res.code === 200) {
        // 关闭对话框并重新查询列表数据

        handleQuery();
        ElMessage.success("该图书上架成功");
        closedialog();
        loading.value = false;
      } else {
        ElMessage.error(res.msg);
        loading.value = false;
      }
    }
  } catch (error) {
    console.error(error);
    // 在发生异常时，取消页面加载状态
    loading.value = false;
  }
};
const change = async (e: any) => {
  Formrule.value.bookLocationId = "";
  Formrule.value.bookshelfId = "";
  const res = await BookshelfOptions(e);
  // console.log(res.data, "weizhi");
  locationOpt.value = res.data;
  // bookshelfList.value = res.data;
  clearBookLocationValidation();
};
// -----------------------------------------------------------------

// 导入
const file = ref();
const OnFile = ref();
const OffFile = ref();
const fileRef = ref();
const OffFileRef = ref();
const OnFileRef = ref();
// 在组件中定义状态变量

const handleFileChange = async (e: any) => {
  const MAX_SIZE = 10 * 1024 * 1024;
  const file = e.target.files[0];
  if (!file) return;

  // 验证文件大小
  if (file.size > MAX_SIZE) {
    alert("文件大小不能超过10MB！");
    return;
  }

  // 验证文件类型
  const allowedExtensions = ["xlsx", "xls"];
  const fileExtension = file.name.split(".").pop().toLowerCase();
  if (!allowedExtensions.includes(fileExtension)) {
    alert("请上传 Excel 文件！");
    return;
  }

  const load = ElLoading.service({
    lock: true,
    text: "正在导入，请稍候...",
    background: "rgba(0, 0, 0, 0.7)",
  });

  try {
    // 模拟耗时操作（实际替换为你的导入逻辑）
    await new Promise((resolve) => setTimeout(resolve, 2000));
    const res = await importLib(file);
    // 导入成功提示
    ElMessage.success(res.msg);
    fileRef.value.value = null;
    handleQuery(); // 刷新数据
    load.close();
  } catch (error) {
    load.close();
    // 导入失败提示
    //console.log(error);
    //ElMessage.info("导入中请耐心等待不要重复导入");
  } finally {
    // 无论成功失败，最后清理状态
    load.close();
    handleQuery(); // 刷新数据
    // 清空文件输入
  }
};
const OnFileChange = async (e: any) => {
  const MAX_SIZE = 10 * 1024 * 1024; // 限制文件大小为 1MB
  OnFile.value = e.target.files[0];
  if (OnFile.value.size > MAX_SIZE) {
    alert("文件大小不能超过10MB！");
    OnFile.value = null;
    return;
  }
  // 检查文件类型是否为 Excel
  const allowedExtensions = ["xlsx", "xls"];
  const fileExtension = OnFile.value.name.split(".").pop().toLowerCase();
  if (!allowedExtensions.includes(fileExtension)) {
    alert("请上传 Excel 文件！");
    file.value = null;
    loading.value = false;
    return;
  }

  //console.log(OnFile.value, "file.value");
  const load = ElLoading.service({
    lock: true,
    text: "Loading",
    background: "rgba(0, 0, 0, 0.7)",
  });
  try {
    const res = await importOnShelf(OnFile.value);

    ElMessage.success(res.msg);
    handleQuery();
    OnFileRef.value.value = null;
    load.close();
  } catch (error) {
    load.close();
    console.error(error);
    // ElMessage.info("上架中请耐心等待不要重复上架");
    handleQuery();
  }
};
const OffFileChange = async (e: any) => {
  const MAX_SIZE = 10 * 1024 * 1024; // 限制文件大小为 1MB
  OffFile.value = e.target.files[0];
  if (OffFile.value.size > MAX_SIZE) {
    alert("文件大小不能超过10MB！");
    OffFile.value = null;
    return;
  }
  // 检查文件类型是否为 Excel
  const allowedExtensions = ["xlsx", "xls"];
  const fileExtension = OffFile.value.name.split(".").pop().toLowerCase();
  if (!allowedExtensions.includes(fileExtension)) {
    alert("请上传 Excel 文件！");
    file.value = null;
    return;
  }

  //console.log(OffFile.value, "file.value");
  const load = ElLoading.service({
    lock: true,
    text: "Loading",
    background: "rgba(0, 0, 0, 0.7)",
  });
  try {
    const res = await importOffShelf(OffFile.value);
    ElMessage.success(res.msg);
    handleQuery();
    OffFileRef.value.value = null; // 清空文件输入框的值，允许重新选择相同文件
    load.close();
  } catch (error) {
    //ElMessage.info("下架中请耐心等待不要重复下架");
    load.close();
    handleQuery();
  }
};
const iptmarker = () => {
  fileRef.value.click();
};
const iptOn = () => {
  OnFileRef.value.click();
};
const iptOff = () => {
  OffFileRef.value.click();
};
const eptBook = () => {
  exportBook(queryParams.keyword, queryParams.bookCode)
    .then((response: any) => {
      const blob = new Blob([response.data], {
        type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8",
      });
      const a = document.createElement("a");
      const href = window.URL.createObjectURL(blob); // 下载的链接
      a.href = href;
      // a.download = decodeURI(
      //   response.headers["content-disposition"].split(";")[1].split("=")[1]
      // );
      a.download = "book";
      // 获取后台设置的文件名称
      document.body.appendChild(a);
      a.click(); // 点击导出
      document.body.removeChild(a); // 下载完成移除元素
      window.URL.revokeObjectURL(href); // 释放掉blob对象
    })
    .catch((error: any) => {
      //console.error("Error exporting book:", error);
    });
};
// 控制序号
const indexMethod = (index: any) => {
  // 1、index:代表当前行数据的下标
  // 2、下标+1:  分页不要纠结：这块不是业务，完全是数学问题！
  return index + 1 + (queryParams.pageNum - 1) * queryParams.pageSize;
};
const isSearchDisabled = computed(() => {
  return !queryParams.bookCode && !queryParams.keyword;
});
const Synchronize = async () => {
  try {
    await ElMessageBox.confirm("确认要同步数据吗?", "警告", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    });

    ElMessage.info("数据同步中，请稍候...");
    await syncBookAdd(useStore.encryptedData);
    //ElMessage.success("数据同步成功");
  } catch {
    //ElMessage.error("数据同步失败，请重试");
  }
};
</script>

<template>
  <div class="app-container">
    <el-dialog
      v-model="dialogVisible"
      :title="title"
      width="550px"
      append-to-body
      @close="close"
    >
      <el-form
        ref="ruleFormRef"
        :model="ruleForm"
        :rules="rules"
        label-width="110px"
        status-icon
      >
        <el-form-item label="图书馆" prop="libraryId">
          <el-select
            v-model="ruleForm.libraryId"
            placeholder="请选择图书馆"
            style="width: 350px"
          >
            <el-option
              v-for="item in LibOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="图书rfid" prop="bookRfid">
          <el-input
            style="width: 350px"
            v-model="ruleForm.bookRfid"
            placeholder="请输入图书rfid"
          />
        </el-form-item>
        <el-form-item label="图书名称" prop="bookName">
          <el-input
            style="width: 350px"
            v-model="ruleForm.bookName"
            placeholder="请输入图书名称"
          />
        </el-form-item>
        <el-form-item label="书脊名称" prop="spineName">
          <el-input
            style="width: 350px"
            v-model="ruleForm.spineName"
            placeholder="请输入书脊名称"
          />
        </el-form-item>
        <el-form-item label="图书编号" prop="bookCode">
          <el-input
            style="width: 350px"
            v-model="ruleForm.bookCode"
            placeholder="请输入图书编号"
          />
        </el-form-item>

        <el-form-item label="图书索引" prop="bookIndex">
          <el-input
            style="width: 350px"
            v-model="ruleForm.bookIndex"
            placeholder="请输入图书索引"
          /> </el-form-item
        ><el-form-item label="图书区域" prop="bookArea">
          <el-input
            style="width: 350px"
            v-model="ruleForm.bookArea"
            placeholder="请输入图书区域"
          />
        </el-form-item>

        <el-form-item label="图书类别" prop="bookCategory">
          <el-input
            style="width: 350px"
            v-model="ruleForm.bookCategory"
            placeholder="请输入图书类别"
          />
        </el-form-item>

        <el-form-item label="图书作者" prop="bookAuthor">
          <el-input
            style="width: 350px"
            v-model="ruleForm.bookAuthor"
            placeholder="请输入图书作者"
          />
        </el-form-item>
        <el-form-item label="出版日期" prop="bookPublishDate">
          <el-input
            style="width: 350px"
            v-model="ruleForm.bookPublishDate"
            placeholder="请输入出版日期"
          />
        </el-form-item>
        <el-form-item label="图书出版社" prop="bookPublisher">
          <el-input
            style="width: 350px"
            v-model="ruleForm.bookPublisher"
            placeholder="请输入图书出版社"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submit">确 定</el-button>
          <el-button @click="close">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <div class="search">
      <el-form ref="queryFormRef" :model="queryParams" :inline="true">
        <el-form-item label="关键字" prop="name">
          <el-input
            v-model="queryParams.keyword"
            placeholder="关键字查询"
            clearable
            @keyup.enter="searchQuery"
          />
        </el-form-item>
        <el-form-item
          label="图书编号"
          prop="name"
          v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
        >
          <el-input
            v-model="queryParams.bookCode"
            placeholder="图书编号查询"
            clearable
            @keyup.enter="searchQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchQuery" icon="Search"
            >搜索</el-button
          >
          <el-button @click="resetQuery" icon="Refresh">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-card>
      <template #header>
        <div
          style="
            display: flex;
            justify-content: space-between;
            align-items: center;
          "
        >
          <div>
            <el-button
              icon="Plus"
              type="success"
              @click="openDialog()"
              v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
              >新增</el-button
            >
            <!--    :disabled="isSearchDisabled" -->
            <el-button
              v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
              type="warning"
              style="margin-left: 10px"
              icon="Download"
              @click="eptBook"
              >图书导出</el-button
            >
            <input
              v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
              ref="fileRef"
              type="file"
              style="display: none"
              @change="handleFileChange"
            />
            <el-button
              v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
              type="warning"
              style="margin-left: 10px"
              icon="Top"
              @click="iptmarker"
              >图书导入</el-button
            >

            <input
              v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
              ref="OnFileRef"
              type="file"
              style="display: none"
              @change="OnFileChange"
            />
            <el-button
              v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
              type="warning"
              style="margin-left: 10px"
              icon="Top"
              @click="iptOn"
              >批量上架</el-button
            >
            <input
              v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
              ref="OffFileRef"
              type="file"
              style="display: none"
              @change="OffFileChange"
            />
            <el-button
              v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
              type="warning"
              style="margin-left: 10px"
              icon="Bottom"
              @click="iptOff"
              >批量下架</el-button
            >
            <el-button
              v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
              type="warning"
              style="margin-left: 10px"
              @click="Synchronize"
              >同步数据</el-button
            >
          </div>
          <div></div>
        </div>

        <!-- <el-button type="danger" :disabled="ids.length === 0" icon="Delete"
          >删除</el-button
        > -->
      </template>
      <el-table
        v-loading="loading"
        highlight-current-row
        :data="tableList"
        :border="true"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="index"
          width="65"
          label="序号"
          :align="'center'"
          :index="indexMethod"
        />
        <!--  <el-table-column type="selection" width="55" align="center" /> > -->
        <el-table-column label="图书名称" prop="bookName" align="center" />
        <el-table-column label="书脊名称" prop="spineName" align="center" />
        <el-table-column label="图书编号" prop="bookCode" align="center" />
        <el-table-column label="RFID编码" prop="bookRfid" align="center" />
        <el-table-column label="图书分类" prop="bookCategory" align="center" />
        <el-table-column label="书架位置" prop="bookshelfName" align="center" />
        <el-table-column label="图书区域" prop="bookArea" align="center" />
        <el-table-column label="图书状态" prop="bookStatus" :align="'center'">
          <template #default="{ row }">
            {{ getbooksStatus(row.bookStatus) }}
          </template>
        </el-table-column>

        <el-table-column
          v-if="hasRole('LIBRARY_ROOT') || hasRole('ADMIN')"
          fixed="right"
          label="操作"
          align="center"
          width="160px"
        >
          <template #default="{ row }">
            <el-button
              type="primary"
              link
              size="small"
              @click="openDialog(row.id)"
              >编辑</el-button
            >
            <el-button type="primary" link size="small" @click="dell(row.id)"
              >删除</el-button
            >
            <el-button
              type="primary"
              link
              size="small"
              @click="editStatus(row)"
            >
              {{ booksStatus(row.bookStatus) }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        style="margin-top: 15px"
        v-model:current-page="queryParams.pageNum"
        v-model:page-size="queryParams.pageSize"
        :page-sizes="[10, 20, 30, 50, 100]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
      v-model="dialog"
      title="图书状态"
      width="500px"
      @close="closedialog"
    >
      <el-form
        ref="FormRef"
        :model="Formrule"
        :rules="rule"
        label-width="110px"
        status-icon
      >
        <el-form-item label="图书馆" prop="libraryId" ref="booklibraryId">
          <el-select
            v-model="Formrule.libraryId"
            placeholder="请选择图书馆"
            @change="change"
          >
            <el-option
              v-for="item in LibOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          ref="bookLocationItem"
          label="书架位置"
          prop="bookshelfId"
          style="white-space: nowrap"
        >
          <el-select
            v-model="Formrule.bookshelfId"
            placeholder="请选择书架位置"
          >
            <el-option
              v-for="item in locationOpt"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="所在书架层数" prop="bookshelfLayer">
          <el-input
            v-model="Formrule.bookshelfLayer"
            placeholder="请输入所在书架层数"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="sbt">确 定</el-button>
          <el-button @click="closedialog">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<style lang="scss" scoped></style>
